package com.hqyj.springtest.mapper.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hqyj.springtest.pojo.School;
import com.hqyj.springtest.service.SchoolService;

@Controller
public class SchoolAjaxController {

	@Autowired
	SchoolService ss;
	
	// -- ��ѯ�����е�ѧУ�����ҽ�ѧУ��������json��ʽ����Ϊ��Ӧ���
	@RequestMapping("query.do")
	@ResponseBody
	public List<School> query(HttpServletRequest request){
		
			 return ss.getAllSchool();
	}
	
	@RequestMapping("add.do")
	@ResponseBody // --Map<String ,String> , ����תΪjson����{"msg":true}
	public Map<String ,Boolean> add(School school){
		int row = ss.addSchool(school);
		Map<String, Boolean> map = new HashMap<String,Boolean>();
		if(row==1) {
			map.put("msg", true);
		}else {
			map.put("msg", false);
		}
		return map;
	}
	
	@RequestMapping("update.do")
	@ResponseBody // --Map<String ,String> , ����תΪjson����{"msg":true}
	public Map<String ,Boolean> udpate(School school){
		int row = ss.updateSchool(school);
		Map<String, Boolean> map = new HashMap<String,Boolean>();
		if(row==1) {
			map.put("msg", true);
		}else {
			map.put("msg", false);
		}
		return map;
	}
	
}
